/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 08/03/2011, 09:06:07
 */

package sisgraf.view;

import com.itextpdf.text.DocumentException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import sisgraf.controler.FichaClienteControler;
import sisgraf.controler.FichaClienteTabela;
import sisgraf.impressao.ImprimePdf;
import sisgraf.model.Cliente;

/**
 *
 * @author jordan
 */
public class FichaCliente extends javax.swing.JDialog {
    private Cliente cliente;
    private FichaClienteControler modeloControler =new FichaClienteControler();
    private FichaClienteTabela modelo;
    
    /** Creates new form Principal */
    public FichaCliente(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        jTbVisualizacao.setModel(modeloControler.getListarFichaCliente(null));
        this.setVisible(true);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPnlSuperior = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPnlCentral = new javax.swing.JPanel();
        jPnlConteudo = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jBtConsultar = new javax.swing.JButton();
        jBtImprimir = new javax.swing.JButton();
        jBtFinalizar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTbVisualizacao = new javax.swing.JTable();
        jTxNom_cli = new javax.swing.JTextField();
        jBtPesquisaCliente = new javax.swing.JButton();
        jPnlControle = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTxFdTotalOrc = new javax.swing.JFormattedTextField();
        jTxFdTotalOrcPend = new javax.swing.JFormattedTextField();
        jTxFdTotalOrcCanc = new javax.swing.JFormattedTextField();
        jTxFdTotalOrcApro = new javax.swing.JFormattedTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jTxFdTotalPed = new javax.swing.JFormattedTextField();
        jTxFdTotalPedPend = new javax.swing.JFormattedTextField();
        jTxFdTotalPedCanc = new javax.swing.JFormattedTextField();
        jTxFdTotalPedEntr = new javax.swing.JFormattedTextField();
        jTxFdTotalPedFatu = new javax.swing.JFormattedTextField();
        jPnlInferior = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ficha de Clientes");
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPnlSuperior.setBorder(new javax.swing.border.MatteBorder(null));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("SISTEMA DE ORÇAMENTOS PARA SERVIÇOS GRAFICOS");
        jLabel1.setMinimumSize(new java.awt.Dimension(0, 14));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Ficha do Cliente");
        jLabel2.setMinimumSize(new java.awt.Dimension(0, 14));

        javax.swing.GroupLayout jPnlSuperiorLayout = new javax.swing.GroupLayout(jPnlSuperior);
        jPnlSuperior.setLayout(jPnlSuperiorLayout);
        jPnlSuperiorLayout.setHorizontalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 752, Short.MAX_VALUE)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 752, Short.MAX_VALUE)
        );
        jPnlSuperiorLayout.setVerticalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlSuperiorLayout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlCentral.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPnlCentral.setMinimumSize(new java.awt.Dimension(100, 0));

        jPnlConteudo.setBorder(javax.swing.BorderFactory.createLineBorder(null));

        jLabel5.setText("Cliente:");

        jBtConsultar.setText("Consultar");
        jBtConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtConsultarActionPerformed(evt);
            }
        });

        jBtImprimir.setText("Imprimir");
        jBtImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtImprimirActionPerformed(evt);
            }
        });

        jBtFinalizar.setText("Finalizar");
        jBtFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtFinalizarActionPerformed(evt);
            }
        });

        jTbVisualizacao.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jTbVisualizacao.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTbVisualizacao);

        jTxNom_cli.setEnabled(false);

        jBtPesquisaCliente.setText("Pesquisar");
        jBtPesquisaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtPesquisaClienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPnlConteudoLayout = new javax.swing.GroupLayout(jPnlConteudo);
        jPnlConteudo.setLayout(jPnlConteudoLayout);
        jPnlConteudoLayout.setHorizontalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxNom_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtPesquisaCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
                .addComponent(jBtConsultar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtImprimir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtFinalizar)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
        );
        jPnlConteudoLayout.setVerticalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxNom_cli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jBtConsultar)
                    .addComponent(jBtImprimir)
                    .addComponent(jBtFinalizar)
                    .addComponent(jBtPesquisaCliente))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlControle.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Orçamentos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

        jLabel6.setText("Total:");

        jLabel7.setText("Pendentes:");

        jLabel8.setText("Cancelados:");

        jLabel9.setText("Aprovados:");

        jTxFdTotalOrc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalOrc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalOrc.setEnabled(false);

        jTxFdTotalOrcPend.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalOrcPend.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalOrcPend.setEnabled(false);

        jTxFdTotalOrcCanc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalOrcCanc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalOrcCanc.setEnabled(false);

        jTxFdTotalOrcApro.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalOrcApro.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalOrcApro.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalOrc, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalOrcPend, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalOrcCanc, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalOrcApro, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(143, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel6)
                .addComponent(jTxFdTotalOrc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel7)
                .addComponent(jTxFdTotalOrcPend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel8)
                .addComponent(jTxFdTotalOrcCanc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel9)
                .addComponent(jTxFdTotalOrcApro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pedidos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

        jLabel10.setText("Total:");

        jLabel11.setText("Pendentes:");

        jLabel12.setText("Cancelados:");

        jLabel13.setText("Entregues");

        jLabel14.setText("Faturados:");

        jTxFdTotalPed.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalPed.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalPed.setEnabled(false);

        jTxFdTotalPedPend.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalPedPend.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalPedPend.setEnabled(false);

        jTxFdTotalPedCanc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalPedCanc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalPedCanc.setEnabled(false);

        jTxFdTotalPedEntr.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalPedEntr.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalPedEntr.setEnabled(false);

        jTxFdTotalPedFatu.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jTxFdTotalPedFatu.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxFdTotalPedFatu.setEnabled(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalPed, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalPedPend, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel12)
                .addGap(7, 7, 7)
                .addComponent(jTxFdTotalPedCanc, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalPedEntr, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxFdTotalPedFatu, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel10)
                .addComponent(jTxFdTotalPed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel11)
                .addComponent(jTxFdTotalPedPend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel12)
                .addComponent(jTxFdTotalPedCanc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel13)
                .addComponent(jTxFdTotalPedEntr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel14)
                .addComponent(jTxFdTotalPedFatu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPnlControleLayout = new javax.swing.GroupLayout(jPnlControle);
        jPnlControle.setLayout(jPnlControleLayout);
        jPnlControleLayout.setHorizontalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPnlControleLayout.setVerticalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlControleLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPnlCentralLayout = new javax.swing.GroupLayout(jPnlCentral);
        jPnlCentral.setLayout(jPnlCentralLayout);
        jPnlCentralLayout.setHorizontalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPnlConteudo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlControle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPnlCentralLayout.setVerticalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlCentralLayout.createSequentialGroup()
                .addComponent(jPnlConteudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlControle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPnlInferior.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("Gráfica Modêlo");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Grupo de Estudo PMA Anhanguera");

        javax.swing.GroupLayout jPnlInferiorLayout = new javax.swing.GroupLayout(jPnlInferior);
        jPnlInferior.setLayout(jPnlInferiorLayout);
        jPnlInferiorLayout.setHorizontalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlInferiorLayout.createSequentialGroup()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 434, Short.MAX_VALUE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPnlInferiorLayout.setVerticalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPnlSuperior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlInferior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlCentral, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPnlSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlCentral, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // TODO add your handling code here:
        int dif = this.getHeight()-jPnlSuperior.getHeight()-jPnlCentral.getHeight()-jPnlInferior.getHeight()-6;
        jPnlCentral.setSize(this.getWidth(),this.getHeight()-jPnlSuperior.getHeight()-jPnlInferior.getHeight()-dif);
        jPnlConteudo.setSize(jPnlCentral.getWidth(),jPnlCentral.getHeight()-jPnlControle.getHeight());
        jPnlControle.setSize(jPnlCentral.getWidth(), jPnlControle.getHeight());
        jPnlControle.setLocation(0, jPnlConteudo.getHeight());
    }//GEN-LAST:event_formComponentResized

    private void jBtPesquisaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtPesquisaClienteActionPerformed
        // TODO add your handling code here:
       PesquisaClientes pesquisaClientes = new PesquisaClientes(new javax.swing.JFrame(), true);
//       cliente = new Cliente();
       pesquisaClientes.setCliente(cliente);
       pesquisaClientes.setOpcao(0);
       cliente = pesquisaClientes.getCliente();
       pesquisaClientes.dispose();
       if (cliente!=null)
          jTxNom_cli.setText(cliente.getNom_cli());

    }//GEN-LAST:event_jBtPesquisaClienteActionPerformed

    private void jBtConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtConsultarActionPerformed
        // TODO add your handling code here:
        String erroMensagem = ""; // jTxFdNumPed
        if (cliente==null){
            erroMensagem = "É necessário selecionar um cliente para consulta";
        }
        String condicao = " i.orcamento.cliente.id = " + cliente.getId().toString();
        if (!erroMensagem.equals("")){
            erroMensagem="Foram encontrados os seguintes erros no filtro de pesquisa:\n"+erroMensagem;
           javax.swing.JOptionPane.showMessageDialog(null, erroMensagem , "Dados Informados Invalidos", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            jTbVisualizacao.setModel(modeloControler.getListarFichaCliente(condicao));
            modeloControler.ajustarTabela(jTbVisualizacao);
            modelo = (FichaClienteTabela) jTbVisualizacao.getModel();
            int nLinhas=modelo.getRowCount();
            BigDecimal totalOrc=new BigDecimal("0");
            BigDecimal totalOrcPend=new BigDecimal("0");
            BigDecimal totalOrcCanc=new BigDecimal("0");
            BigDecimal totalOrcApro=new BigDecimal("0");
            BigDecimal totalPed=new BigDecimal("0");
            BigDecimal totalPedPend=new BigDecimal("0");
            BigDecimal totalPedCanc=new BigDecimal("0");
            BigDecimal totalPedEntr=new BigDecimal("0");
            BigDecimal totalPedFatu=new BigDecimal("0");
            for (int i=0;i<nLinhas;i++){
                totalOrc=totalOrc.add(modelo.getFichaCliente(i).getItemOrcamento().getValor());
                if (modelo.getFichaCliente(i).getItemOrcamento().getDataAprovacao()==null)
                    totalOrcPend=totalOrcPend.add(modelo.getFichaCliente(i).getItemOrcamento().getValor());
                if (modelo.getFichaCliente(i).getItemOrcamento().getDataCancelamento()!=null)
                    totalOrcCanc=totalOrcCanc.add(modelo.getFichaCliente(i).getItemOrcamento().getValor());
                if (modelo.getFichaCliente(i).getItemOrcamento().getDataAprovacao()!=null)
                    totalOrcApro=totalOrcApro.add(modelo.getFichaCliente(i).getItemOrcamento().getValor());
                if (modelo.getFichaCliente(i).getPedido()!=null){
                    totalPed=totalPed.add(modelo.getFichaCliente(i).getPedido().getValor());
                    if (modelo.getFichaCliente(i).getPedido().getDataEntrega()==null&&
                            modelo.getFichaCliente(i).getPedido().getDataCancelamento()==null)
                        totalPedPend=totalPedPend.add(modelo.getFichaCliente(i).getPedido().getValor());
                    if (modelo.getFichaCliente(i).getPedido().getDataCancelamento()!=null)
                        totalPedCanc=totalPedCanc.add(modelo.getFichaCliente(i).getPedido().getValor());
                    if (modelo.getFichaCliente(i).getPedido().getDataEntrega()!=null)
                        totalPedEntr=totalPedEntr.add(modelo.getFichaCliente(i).getPedido().getValor());
                    if (modelo.getFichaCliente(i).getPedido().getDataFaturamento()!=null)
                        totalPedFatu=totalPedFatu.add(modelo.getFichaCliente(i).getPedido().getValor());
                }
//                total=total.add(modelo.getFichaCliente(i).getPedido().getValor());
            }
            jTxFdTotalOrc.setText(totalOrc.toString());
            jTxFdTotalOrcPend.setText(totalOrcPend.toString());
            jTxFdTotalOrcCanc.setText(totalOrcCanc.toString());
            jTxFdTotalOrcApro.setText(totalOrcApro.toString());
            jTxFdTotalPed.setText(totalPed.toString());
            jTxFdTotalPedPend.setText(totalPedPend.toString());
            jTxFdTotalPedCanc.setText(totalPedCanc.toString());
            jTxFdTotalPedEntr.setText(totalPedEntr.toString());
            jTxFdTotalPedFatu.setText(totalPedFatu.toString());
        }

    }//GEN-LAST:event_jBtConsultarActionPerformed

    private void jBtFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtFinalizarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jBtFinalizarActionPerformed

    private void jBtImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtImprimirActionPerformed
        // TODO add your handling code here:
         if(jTbVisualizacao.getRowCount()==0)
         JOptionPane.showMessageDialog(null,"Não há dados para impressão!");
     else
     {
        ArrayList lista = new ArrayList();
        ArrayList lista1 = new ArrayList();
        ArrayList lista2 = new ArrayList();
        int i=0,j=0;
        for(j=0;j<jTbVisualizacao.getColumnCount();j++)
            lista.add(jTbVisualizacao.getColumnName(j));
        for(i=0;i<jTbVisualizacao.getRowCount();i++)
            for(j=0;j<jTbVisualizacao.getColumnCount();j++)
            lista.add(jTbVisualizacao.getValueAt(i,j));
        lista1.add(jTxFdTotalOrc.getText());
        lista1.add(jTxFdTotalOrcPend.getText());
        lista1.add(jTxFdTotalOrcCanc.getText());
        lista1.add(jTxFdTotalOrcApro.getText());

        lista2.add(jTxFdTotalPed.getText());
        lista2.add(jTxFdTotalPedPend.getText());
        lista2.add(jTxFdTotalPedCanc.getText());
        lista2.add(jTxFdTotalPedEntr.getText());
        lista2.add(jTxFdTotalPedFatu.getText());

    ImprimePdf impr = new ImprimePdf();
            try {
                impr.imprimir(lista, jTbVisualizacao.getColumnCount(), "Ficha de Clientes", null, false,true,lista1,lista2);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(FichaCliente.class.getName()).log(Level.SEVERE, null, ex);
            } catch (DocumentException ex) {
                Logger.getLogger(FichaCliente.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(FichaCliente.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jBtImprimirActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Principal dialog = new Principal(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtConsultar;
    private javax.swing.JButton jBtFinalizar;
    private javax.swing.JButton jBtImprimir;
    private javax.swing.JButton jBtPesquisaCliente;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPnlCentral;
    private javax.swing.JPanel jPnlConteudo;
    private javax.swing.JPanel jPnlControle;
    private javax.swing.JPanel jPnlInferior;
    private javax.swing.JPanel jPnlSuperior;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTbVisualizacao;
    private javax.swing.JFormattedTextField jTxFdTotalOrc;
    private javax.swing.JFormattedTextField jTxFdTotalOrcApro;
    private javax.swing.JFormattedTextField jTxFdTotalOrcCanc;
    private javax.swing.JFormattedTextField jTxFdTotalOrcPend;
    private javax.swing.JFormattedTextField jTxFdTotalPed;
    private javax.swing.JFormattedTextField jTxFdTotalPedCanc;
    private javax.swing.JFormattedTextField jTxFdTotalPedEntr;
    private javax.swing.JFormattedTextField jTxFdTotalPedFatu;
    private javax.swing.JFormattedTextField jTxFdTotalPedPend;
    private javax.swing.JTextField jTxNom_cli;
    // End of variables declaration//GEN-END:variables
    
}
